package com.c.ctgproject.ui.sell

import android.app.Activity
import android.content.Intent
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseActivity
import com.c.ctgproject.mode.MyConstants
import com.c.ctgproject.ui.review.material.MaterialReviewActivity
import com.c.ctgproject.ui.review.part.PartReviewActivity
import com.c.ctgproject.ui.sell.material.MaterialDetailActivity
import com.c.ctgproject.ui.sell.material.MaterialSellListActivity
import com.c.ctgproject.ui.sell.parts.PartsSellActivity
import com.c.ctgproject.ui.sell.parts.PartsSellListActivity
import com.c.ctgproject.ui.sell.parts.SellerScanActivity
import com.c.ctgproject.utils.*
import com.c.ctgproject.utils.showPopupWindow
import com.yzq.zxinglibrary.common.Constant
import kotlinx.android.synthetic.main.activity_sell.*
import org.jetbrains.anko.startActivity

/**
 *作者:LiBW
 *创建日期: 2020/9/2
 *描述: 销售 页面
 */
class SellHomeActivity : BaseActivity() {
    override fun getLayout() = R.layout.activity_sell

    override fun event() {
        changeTransparentStatusBar()
    }

    override fun click() {
        mSettingIV.setOnClickListener {
            showPopupWindow(mSettingIV)
        }
        //物料销售
        mMaterialSellLL.setOnClickListener {
            startActivity<MaterialSellListActivity>()
        }
        //物料销售列表
        mMaterialSellLLDetailLL.setOnClickListener {
            startActivity<MaterialDetailActivity>()
        }
        //配件销售列表
        mPartSellLL.setOnClickListener {
            startActivity<PartsSellListActivity>()
        }
        //物料申请结果
        mApplyMaterialResultLL.setOnClickListener {
            startActivity<MaterialReviewActivity>(MyConstants.JUST_SHOW to true)
        }
        //配件申请结果
        mApplyPartsResultLL.setOnClickListener {
            startActivity<PartReviewActivity>(MyConstants.JUST_SHOW to true)
        }
        //扫码
        mScanQrIV.setOnClickListener {
            scanQr()
        }
        //配件销售
        mPartSellInLL.setOnClickListener {
            startActivity<PartsSellActivity>()
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK && requestCode == QR_CODE_RESULT && data != null) {
            val content: String? = data.getStringExtra(Constant.CODED_CONTENT)
            content?.let {
                MyLog.d("二维码信息:$it")
                val strList = it.split(":")
                if (strList[0] == "carCode") {
                    startActivity<SellerScanActivity>(MyConstants.CAR_CODE to strList[1])
                } else {
                    CustomToast.showToast(this, "请扫拓号单二维码")
                }
            }
        }
    }


    override fun onBackPressed() {
        exitApp()
    }
}